import java.util.*;
public class Practice1{
    //https://ac.nowcoder.com/acm/problem/16693
    //01背包问题
    //空间优化版本
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = sc.nextInt();
        }
        //前i个物品中挑选,满足体积为j的,是多少
        boolean[] dp = new boolean[v + 1];
        dp[0] = true;
        for(int j = 1;j <= v;j++){
            dp[j] = false;
        }
        for(int i = 1;i <= n;i++){
            for(int j = v;j >= arr[i - 1];j--){
                if(!dp[j]){
                    dp[j] = dp[j - arr[i - 1]];
                }
            }
        }
        int max = -1;
        for(int j = 1;j <= v;j++){
            if(dp[j]){
                max = Math.max(max,j);
            }
        }
        System.out.println(max == -1 ? v : v - max);
    }
    //正常版本
    public static void main1(String[] args){
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = sc.nextInt();
        }
        //前i个物品中挑选,满足体积为j的,是多少
        boolean[][] dp = new boolean[n + 1][v + 1];
        for(int i = 0;i <= n;i++){
            dp[i][0] = true;
        }
        for(int j = 1;j <= v;j++){
            dp[0][j] = false;
        }
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= v;j++){
                dp[i][j] = dp[i - 1][j];
                if(j - arr[i - 1] >= 0 && !dp[i][j]){
                    dp[i][j] = dp[i - 1][j - arr[i - 1]];
                }
            }
        }
        int max = -1;
        for(int j = 1;j <= v;j++){
            if(dp[n][j]){
                max = Math.max(max,j);
            }
        }
        System.out.println(max == -1 ? v : v - max);
    }
}